package com.example.fw;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


//lesson 4 ~ 66:00

public class Groups {

	private Set<GroupObject> storedGroups = null;
	
	public Groups (Collection<GroupObject> groups)	{		// lesson 7 - 43:30 - List<GroupObject> to Groups, consult 9 (question 2)
		storedGroups = new HashSet<GroupObject>(groups);
	}
	
	public Groups withAdded(GroupObject group) {
		Groups groups = new Groups(storedGroups);
		//group.setId("$$$");
		groups.storedGroups.add(group);
		//group.setId(null);
		return groups;
	}

	public Groups withOut(GroupObject group) {
		Groups groups = new Groups(storedGroups);
		groups.storedGroups.remove(group);
		return groups;
	}
	
	public GroupObject getSomeGroupFromList() {
		GroupObject someGroupFromList = storedGroups.iterator().next();
		return someGroupFromList;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((storedGroups == null) ? 0 : storedGroups.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Groups other = (Groups) obj;
		if (storedGroups == null) {
			if (other.storedGroups != null)
				return false;
		} else if (!storedGroups.equals(other.storedGroups))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "Groups [storedGroups=" + storedGroups + "]";
	}
}